{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from pynq import Overlay\n",
    "ol = Overlay(\"/home/xilinx/pynq/bitstream/top.bit\")\n",
    "\n",
    "ol.download()\n",
    "ol.bitstream.timestamp\n",
    "\n",
    "from pynq import PL\n",
    "PL.bitfile_name\n",
    "\n",
    "ol.is_loaded()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "BASE_ADDRESS = 0x46000000\n",
    "        \n",
    "from pynq import MMIO\n",
    "  \n",
    "class part158:\n",
    "    \"\"\"Brief description of Module goes here.\n",
    "    \n",
    "    Attributes\n",
    "    ----------\n",
    "    array_size : int\n",
    "       Describe  parameters used in this module's functions.\n",
    "    raw_data : int\n",
    "       Input Data\n",
    "    processed_data : int\n",
    "       Return data\n",
    "       \n",
    "   \"\"\"\n",
    "    mmio = MMIO(0x46000000,0x00002000)\n",
    "    array_length = 0\n",
    " \n",
    "    def __init__(self):\n",
    "        self.mmio.write(0, 0)\n",
    "     \n",
    "    def load_data(self, raw_data):\n",
    "        self.array_length = len(raw_data)\n",
    "        for i in range(0 , self.array_length):\n",
    "            self.mmio.write(i*4, raw_data[i])\n",
    "            \n",
    "    def read_data(self):     \n",
    "        processed_data = [0] *self.array_length\n",
    "\n",
    "        for i in range(0 , self.array_length):\n",
    "            processed_data[i] = self.mmio.read(i*4)\n",
    "        return processed_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Input Data     :  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n",
      "Processed Data :  [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]\n",
      "Input Data     :  [5708, 16605, 21073, 25713, 28497, 10668, 10142, 16963, 19694, 26826, 21412, 19013, 24907, 3442, 19521, 12100, 24205, 1808, 11433, 26451]\n",
      "Processed Data :  [5708, 16605, 21073, 25713, 28497, 10668, 10142, 16963, 19694, 26826, 21412, 19013, 24907, 3442, 19521, 12100, 24205, 1808, 11433, 26451]\n"
     ]
    }
   ],
   "source": [
    "# declare acc with a Maximum allowable array size\n",
    "acc = part158()\n",
    "raw_data = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]\n",
    "#print(\"Some data to be sent to the accelerator:\", raw_data)\n",
    "acc.load_data(raw_data)\n",
    "processed_data = acc.read_data()\n",
    "print(\"Input Data     : \", raw_data)\n",
    "print(\"Processed Data : \", processed_data)\n",
    "\n",
    "import random\n",
    "array_length = len(raw_data)\n",
    "for i in range (0 , array_length):\n",
    "    raw_data[i] = random.randint(0, 32767)\n",
    "acc.load_data(raw_data)\n",
    "processed_data = acc.read_data()\n",
    "print(\"Input Data     : \", raw_data)\n",
    "print(\"Processed Data : \", processed_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
